﻿namespace LinqEx.Tests
{
	using Microsoft.VisualStudio.TestTools.UnitTesting;
	using System;
	using System.IO;
	using System.Linq;
	
	[TestClass]
	public class StreamExtensionTests
	{
		[TestMethod]
		public void AsTextLines()
		{
			string candidate = @"First line
Second line
Third line";

			using (Stream stream = new MemoryStream())
			using (StreamWriter writer = new StreamWriter(stream))
			{
				writer.Write(candidate);
				writer.Flush();
				stream.Seek(0L, SeekOrigin.Begin);

				string[] result = stream.AsTextLines().ToArray();

				CollectionAssert.AreEqual(result, new[] { "First line", "Second line", "Third line" });
			}
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void AsTextLines_StreamIsNull()
		{
			StreamExtensions.AsTextLines(null).GetEnumerator().MoveNext();
		}
	}
}
